package com.zqxq.lottery.api.config;

import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

@ConfigurationProperties(prefix = "alipay-config")
@Component("alipayConfig")
@Data
@Slf4j
public class AlipayConfig implements InitializingBean {

    public static final String CONFIG_EXCEPTION = "配置参数不能为null";
    private String serverUrl;
    private String appId;//应用ID
    private String pId;//用户账号
    private String privateKey;
    private String publicKey;
    private String charset;
    private String notityUrl;//本地测试环境
    private String returnUrl;

    @Override
    public void afterPropertiesSet() throws Exception {
        if(null == serverUrl || "".equals(serverUrl.trim())) {
            throw new IllegalArgumentException("serverUrl"+CONFIG_EXCEPTION);
        }

        if(null == appId || "".equals(appId.trim())) {
            throw new IllegalArgumentException("appId"+CONFIG_EXCEPTION);
        }

        if(null == pId || "".equals(pId.trim())) {
            throw new IllegalArgumentException("pId"+CONFIG_EXCEPTION);
        }
        if(null == privateKey || "".equals(privateKey.trim())) {
            throw new IllegalArgumentException("privateKey"+CONFIG_EXCEPTION);
        }
        if(null == publicKey || "".equals(publicKey.trim())) {
            throw new IllegalArgumentException("publicKey"+CONFIG_EXCEPTION);
        }

        if(null == charset || "".equals(charset.trim())) {
            throw new IllegalArgumentException("charset"+CONFIG_EXCEPTION);
        }

    }

}
